import request from '@/utils/request'

// ==================== 商品管理 ====================

// 获取商品列表
export function getProductList(params) {
  return request({
    url: '/api/zenithMind/mall/products',
    method: 'get',
    params
  })
}

// 获取商品详情
export function getProductDetail(id) {
  return request({
    url: `/api/zenithMind/mall/products/${id}`,
    method: 'get'
  })
}

// 搜索商品
export function searchProducts(keyword, params) {
  return request({
    url: '/api/zenithMind/mall/products/search',
    method: 'get',
    params: { keyword, ...params }
  })
}

// 获取热门商品
export function getHotProducts(limit = 10) {
  return request({
    url: '/api/zenithMind/mall/products/hot',
    method: 'get',
    params: { limit }
  })
}

// 获取推荐商品
export function getRecommendProducts(limit = 10) {
  return request({
    url: '/api/zenithMind/mall/products/recommend',
    method: 'get',
    params: { limit }
  })
}

// 按分类获取商品
export function getProductsByCategory(categoryId, params) {
  return request({
    url: `/api/zenithMind/mall/products/category/${categoryId}`,
    method: 'get',
    params
  })
}

// 收藏商品
export function favoriteProduct(productId) {
  return request({
    url: `/api/zenithMind/mall/products/${productId}/favorite`,
    method: 'post'
  })
}

// 取消收藏
export function unfavoriteProduct(productId) {
  return request({
    url: `/api/zenithMind/mall/products/${productId}/unfavorite`,
    method: 'post'
  })
}

// 获取收藏商品
export function getFavoriteProducts(params) {
  return request({
    url: '/api/zenithMind/mall/products/favorites',
    method: 'get',
    params
  })
}

// 获取相关商品
export function getRelatedProducts(productId, limit = 6) {
  return request({
    url: `/api/zenithMind/mall/products/${productId}/related`,
    method: 'get',
    params: { limit }
  })
}

// 获取推荐商品（用于购物车页面）
export function getRecommendedProducts(params) {
  return request({
    url: '/api/zenithMind/mall/products/recommended',
    method: 'get',
    params
  })
}

// ==================== 购物车管理 ====================

// 获取购物车
export function getCart() {
  return request({
    url: '/api/zenithMind/mall/cart',
    method: 'get'
  })
}

// 添加到购物车
export function addToCart(data) {
  return request({
    url: '/api/zenithMind/mall/cart/add',
    method: 'post',
    data
  })
}

// 更新购物车商品数量
export function updateCartItem(itemId, data) {
  return request({
    url: `/api/zenithMind/mall/cart/items/${itemId}`,
    method: 'put',
    data
  })
}

// 删除购物车商品
export function removeCartItem(itemId) {
  return request({
    url: `/api/zenithMind/mall/cart/items/${itemId}`,
    method: 'delete'
  })
}

// 清空购物车
export function clearCart() {
  return request({
    url: '/api/zenithMind/mall/cart/clear',
    method: 'delete'
  })
}

// ==================== 订单管理 ====================

// 创建订单
export function createOrder(data) {
  return request({
    url: '/api/zenithMind/mall/orders',
    method: 'post',
    data
  })
}

// 获取我的订单
export function getMyOrders(params) {
  return request({
    url: '/api/zenithMind/mall/orders/my',
    method: 'get',
    params
  })
}

// 获取订单详情
export function getOrderDetail(orderId) {
  return request({
    url: `/api/zenithMind/mall/orders/${orderId}`,
    method: 'get'
  })
}

// 取消订单
export function cancelOrder(orderId) {
  return request({
    url: `/api/zenithMind/mall/orders/${orderId}/cancel`,
    method: 'post'
  })
}

// 确认收货
export function confirmReceive(orderId) {
  return request({
    url: `/api/zenithMind/mall/orders/${orderId}/confirm`,
    method: 'post'
  })
}

// 获取商品分类列表
export function getProductCategories() {
  return request({
    url: '/api/zenithMind/mall/categories',
    method: 'get'
  })
}

// 获取商品分类详情
export function getProductCategory(categoryId) {
  return request({
    url: `/api/zenithMind/mall/categories/${categoryId}`,
    method: 'get'
  })
}

// 根据分类获取商品
export function getProductsByCategory(categoryId, params) {
  return request({
    url: `/api/zenithMind/mall/categories/${categoryId}/products`,
    method: 'get',
    params
  })
}

// 申请退款
export function requestRefund(orderId, reason) {
  return request({
    url: `/api/zenithMind/mall/orders/${orderId}/refund`,
    method: 'post',
    data: { reason }
  })
}

// 支付订单
export function payOrder(orderId, paymentMethod) {
  return request({
    url: `/api/zenithMind/mall/orders/${orderId}/pay`,
    method: 'post',
    data: { paymentMethod }
  })
}

// ==================== 商品分类 ====================

// 获取商品分类
export function getProductCategories() {
  return request({
    url: '/api/zenithMind/mall/categories',
    method: 'get'
  })
}

// 获取分类树
export function getProductCategoryTree() {
  return request({
    url: '/api/zenithMind/mall/categories/tree',
    method: 'get'
  })
}

// ==================== 商品评价 ====================

// 获取商品评价
export function getProductReviews(productId, params) {
  return request({
    url: `/api/zenithMind/mall/product-reviews/product/${productId}`,
    method: 'get',
    params
  })
}

// 添加评价
export function addProductReview(data) {
  return request({
    url: '/api/zenithMind/mall/product-reviews',
    method: 'post',
    data
  })
}

// 点赞评价
export function likeProductReview(reviewId) {
  return request({
    url: `/api/zenithMind/mall/product-reviews/${reviewId}/like`,
    method: 'post'
  })
}

// ==================== 地址管理 ====================

// 获取收货地址
export function getAddresses() {
  return request({
    url: '/api/zenithMind/mall/addresses',
    method: 'get'
  })
}

// 添加收货地址
export function addAddress(data) {
  return request({
    url: '/api/zenithMind/mall/addresses',
    method: 'post',
    data
  })
}

// 更新收货地址
export function updateAddress(addressId, data) {
  return request({
    url: `/api/zenithMind/mall/addresses/${addressId}`,
    method: 'put',
    data
  })
}

// 删除收货地址
export function deleteAddress(addressId) {
  return request({
    url: `/api/zenithMind/mall/addresses/${addressId}`,
    method: 'delete'
  })
}

// 设置默认地址
export function setDefaultAddress(addressId) {
  return request({
    url: `/api/zenithMind/mall/addresses/${addressId}/default`,
    method: 'post'
  })
}

// ==================== 优惠券管理 ====================

// 获取可用优惠券
export function getAvailableCoupons() {
  return request({
    url: '/api/zenithMind/mall/coupons/available',
    method: 'get'
  })
}

// 领取优惠券
export function claimCoupon(couponId) {
  return request({
    url: `/api/zenithMind/mall/coupons/${couponId}/claim`,
    method: 'post'
  })
}

// 获取我的优惠券
export function getMyCoupons(params) {
  return request({
    url: '/api/zenithMind/mall/coupons/my',
    method: 'get',
    params
  })
}

// ==================== 库存管理 ====================

// 检查商品库存
export function checkStock(productId, quantity) {
  return request({
    url: `/api/zenithMind/mall/products/${productId}/stock`,
    method: 'get',
    params: { quantity }
  })
}

// ==================== 物流管理 ====================

// 获取物流信息
export function getLogistics(orderId) {
  return request({
    url: `/api/zenithMind/mall/orders/${orderId}/logistics`,
    method: 'get'
  })
}
